package com.jfirer.validator.descriptor;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.CrossParameterDescriptor;

public class CrossParameterDescriptorImpl extends ElementDescriptorImpl implements CrossParameterDescriptor
{
    public CrossParameterDescriptorImpl(AccessibleObject accessibleObject, Set<ConstraintDescriptor<?>> constraintDescriptors)
    {
        if (accessibleObject instanceof Method)
        {
            Method method = (Method) accessibleObject;
            if (method.getParameterTypes().length == 0)
            {
                initializeElementDescriptor(null, new HashSet<ConstraintDescriptor<?>>());
                return;
            }
            initializeElementDescriptor(method.getParameterTypes().getClass(), Collections.unmodifiableSet(constraintDescriptors));
        }
        else if (accessibleObject instanceof Constructor<?>)
        {
            Constructor<?> constructor = (Constructor<?>) accessibleObject;
            initializeElementDescriptor(constructor.getDeclaringClass(), Collections.unmodifiableSet(constraintDescriptors));
        }
    }
    
}
